package bluerain.io.activity.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

import bluerain.io.activity.R;
import bluerain.io.activity.entries.Person;

/**
 * Created by foredawn on 15-9-12.
 * activity之间的数据传递
 */
public class RegisterActivityTest extends Activity {

    Button regBtn;
    RadioButton rbMale;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_activity);
        regBtn = (Button) findViewById(R.id.reg_btn);
        rbMale = (RadioButton) findViewById(R.id.male);
        regBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(RegisterActivityTest.this, RegisterSuccessActivity.class);
                intent.putExtras(getPersonBundle());
                startActivity(intent);
            }
        });
    }

    //返回当前用户信息至前一个调用此窗口的Activity
    public void result(View source) {
        Intent intent = getIntent();
        intent.putExtras(getPersonBundle());
        setResult(0, intent);//返回结果
        finish();
    }

    private Bundle getPersonBundle() {
        String name = ((EditText) findViewById(R.id.reg_name)).getText().toString();
        String pass = ((EditText) findViewById(R.id.reg_pass)).getText().toString();
        String gender = rbMale.isChecked() ? "男" : "女";
        Person person = new Person(name, pass, gender);
        Bundle bundle = new Bundle();
        bundle.putSerializable("person", person);
        return bundle;

    }
}
